Lesson 5: Building a maze and
Competition
Introduction to this lesson
In
this lesson we will cover how to build a maze using the skills you have learnt
in the previous chapters. You will then be tasked for building a maze given a
specific set of rules (such as having using a maximum of 100 blocks). You will
then be able to compete with fellow students to see who can escape the mazes
the quickest.
Building the maze
In
this final lesson, you will learn how to build a maze in Python for Minecraft. Although the task may sound difficult, it in
fact builds on everything you have learnt in the previous lessons. You can
refer to them at any time to help you build the maze.
The
easiest way to start building a maze is by creating blocks that act as the
edges of the paths inside the maze.
For
example:
mc.setBlock(0,1,1,block.WOOL.id)
This
will create a block of grass at position 0 blocks along the x-axis, 1 block
along the y-axis and 1 block along the z-axis. You can even change the color of
the block by adding a number after the id.
For
example:
mc.setBlock(0,1,2,block.WOOL.id.12)
This
would create a brown-coloured block of wool. (Note:
make sure to import the relevant libraries at the top of the program file in
order for the functions to work).
In
theory, you could now create a maze just by re-writing the above lines of code
and changing the x,y and z
position of each block. However, that can be very tedious especially if you
want to add a large number of blocks! An easier way of doing it is by
implementing a recursive function that can help create longer stretches of
blocks, such as walls, like in lesson 3.
For
example:
1 for y in Range(0, 5):
2 if y ==
0 or y == 5:
3 for
x in Range(0, 2):
4 mc.setBlock(x,
y, 1, stone)
5 else:
6 mc.setBlock(0,
y, 1, stone)
7 mc.setBlock(2,
y, 1, stone)
This
would create the structure seen below. You can notice that we have created a
one-path maze surrounded by walls on all sides! (In practice, you may want to
include an entrance and exit to the maze)
Maze task and competition!
Your
task is to build a maze using a maximum of 100 blocks (remember you can build
walls using iterative functions but each square counts as one block).
Once
you have built your maze you can then proceed on to the competition stage: find
another classmate who has already completed a maze and see who can escape each
other’s maze the quickest! (I.e. you try out your classmate’s maze and they try
out yours). The winner is the one who escapes the maze first!
Maze extension
If
you want to further explore mazes and their construction, try building an even
bigger maze! For example, by using 1000 blocks. At this point you could try testing
if you can complete the maze yourself, as the sheer size of it will make it
harder for you to memorize the paths. It will also be useful in checking that
you can reach the exit of the maze from the entrance!